package com.hpdz.hotel_back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hpdz.hotel_back.config.RoomState;
import com.hpdz.hotel_back.entity.Room;
import com.hpdz.hotel_back.mapper.RoomMapper;
import com.hpdz.hotel_back.service.RoomService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Transactional
@Service
public class RoomServiceImpl extends ServiceImpl<RoomMapper, Room> implements RoomService {

    @Resource
    private RoomMapper roomMapper;

    @Override
    public IPage<Room> listPage(Integer current, Integer size) {
        Page<Room> page = new Page<>(current, size);
        LambdaQueryWrapper<Room> roomLambdaQueryWrapper = new LambdaQueryWrapper<>();
        roomLambdaQueryWrapper.eq(true,Room::getState, RoomState.leisure);
        return roomMapper.selectPage(page,roomLambdaQueryWrapper);
    }

    @Override
    public IPage<Room> findPage(Integer current, Integer size, Room room) {
        Page<Room> page = new Page<>(current, size);
        LambdaQueryWrapper<Room> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(room.getRoomNumb() != null,Room::getRoomNumb,room.getRoomNumb());
        return roomMapper.selectPage(page,wrapper);
    }
}
